package com.ruoyi.inventory.util;

import com.ruoyi.inventory.domain.TWhWarehouse;
import com.ruoyi.inventory.domain.dto.WarehouseDTO;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 仓库转换工具类
 * 用于TWhWarehouse和WarehouseDTO之间的转换
 * 
 * @author ruoyi
 * @date 2025-01-15
 */
public class WarehouseConverter 
{
    /**
     * TWhWarehouse转换为WarehouseDTO
     */
    public static WarehouseDTO toDTO(TWhWarehouse warehouse) 
    {
        if (warehouse == null) {
            return null;
        }
        
        WarehouseDTO dto = new WarehouseDTO();
        dto.setWarehouseCode(warehouse.getCode());
        dto.setWarehouseName(warehouse.getName());
        dto.setEnabled(warehouse.getEnabled());
        dto.setIsDelete(warehouse.getIsDelete());
        dto.setCreatedAt(warehouse.getCreatedAt());
        dto.setUpdatedAt(warehouse.getUpdatedAt());
        dto.setRemark(warehouse.getRemark());
        return dto;
    }

    /**
     * WarehouseDTO转换为TWhWarehouse
     */
    public static TWhWarehouse toEntity(WarehouseDTO dto) 
    {
        if (dto == null) {
            return null;
        }
        
        TWhWarehouse warehouse = new TWhWarehouse();
        warehouse.setCode(dto.getWarehouseCode());
        warehouse.setName(dto.getWarehouseName());
        warehouse.setEnabled(dto.getEnabled());
        warehouse.setIsDelete(dto.getIsDelete());
        warehouse.setCreatedAt(dto.getCreatedAt());
        warehouse.setUpdatedAt(dto.getUpdatedAt());
        warehouse.setRemark(dto.getRemark());
        return warehouse;
    }

    /**
     * TWhWarehouse列表转换为WarehouseDTO列表
     */
    public static List<WarehouseDTO> toDTOList(List<TWhWarehouse> warehouses) 
    {
        if (warehouses == null) {
            return null;
        }
        
        return warehouses.stream()
                .map(WarehouseConverter::toDTO)
                .collect(Collectors.toList());
    }

    /**
     * WarehouseDTO列表转换为TWhWarehouse列表
     */
    public static List<TWhWarehouse> toEntityList(List<WarehouseDTO> dtos) 
    {
        if (dtos == null) {
            return null;
        }
        
        return dtos.stream()
                .map(WarehouseConverter::toEntity)
                .collect(Collectors.toList());
    }
}
